<?php
class EditIssueForm extends Zend_Form
{
	public function init()
	{
		$fronController = Zend_Controller_Front::getInstance();
		$request = $fronController->getRequest();
		$issueId = $request->getParam('issueId');
		
		$issue = new Issue();
		$pid = $issue->getAdapter()->fetchOne($issue->select()->from('issue','project')
															->where('id=?',$issueId));
		$users = new UserBase();
		$usersList = $users->getUsersList();
		
		
		$Priority = new Priority();
		$priorityList = $Priority->getList();

		$Component = new Component();
		$componentList = $Component->getList($pid);
		
		$projectVersion = new ProjectVersion();
		$versionsList = $projectVersion->getList($pid);
		
		$id = $this->createElement('hidden','id');
		$id->setValue("")
				->setDecorators(array(
							'viewHelper',
							'Errors',
							array('Description', array('tag'=>'', 'escape'=>false)),
							array(array('data'=>'HtmlTag'),
								array('tag'=>'td', 'valign'=>'top','colspan'=>2,'style'=>'background-color:#ffffff')),
							//array('Label', array('tag'=>'td')),
							array(array('row'=>'HtmlTag'), array('tag'=>'tr'))
				));
				
		$issuestatus = $this->createElement('hidden','issuestatus');
		$issuestatus->setValue("")
				->setDecorators(array(
							'viewHelper',
							'Errors',
							array('Description', array('tag'=>'', 'escape'=>false)),
							array(array('data'=>'HtmlTag'),
								array('tag'=>'td', 'valign'=>'top','colspan'=>2,'style'=>'background-color:#ffffff')),
							//array('Label', array('tag'=>'td')),
							array(array('row'=>'HtmlTag'), array('tag'=>'tr'))
				));
				
		$resolution = $this->createElement('hidden','resolution');
		$resolution->setValue("")
				->setDecorators(array(
							'viewHelper',
							'Errors',
							array('Description', array('tag'=>'', 'escape'=>false)),
							array(array('data'=>'HtmlTag'),
								array('tag'=>'td', 'valign'=>'top','colspan'=>2,'style'=>'background-color:#ffffff')),
							//array('Label', array('tag'=>'td')),
							array(array('row'=>'HtmlTag'), array('tag'=>'tr'))
				));
		
		$summary = $this->createElement('text','summary');
		$summary->setLabel('* Summary:')
				->setRequired(true)
				->setAttrib('style','width:90%');
				
		$affectVersions = $this->createElement('multiselect','affectVersions');
		$affectVersions->setLabel('Affect Version/s:')
					->addMultioption('','Unreleased Versions')
					->addMultioptions($versionsList);
					
		$fixVersions = $this->createElement('multiselect','fixVersions');
		$fixVersions->setLabel('Fix Version/s:')
					->addMultioption('','Unreleased Versions')
					->addMultioptions($versionsList);
		
		$priority = $this->createElement('select','priority');
		$priority->setLabel('Priority:')
				->setAttrib('class','imagebacked priority_list')
				->addMultioptions($priorityList);
		
		$duedate = $this->createElement('text','duedate');
		$duedate->setLabel('Due Date:');
		
		$components = $this->createElement('multiselect','components');
		$components->setLabel('Component/s:')
					->addMultioptions($componentList)
					->addMultioption('','Unknown');
		
		$assignee = $this->createElement('select','assignee');
		$assignee->setLabel('Assignee:')
					->addMultioption('','- Automatic -')
					->addMultioptions($usersList);
		
		$reporter = $this->createElement('text','reporter');
		$reporter->setLabel('* Reporter:')
				->setDescription('<div id="userscontainer"></div><font size = "1"><br>Start typing to get a list of possible matches.</font>')
				->setRequired(true);
		
		$description = $this->createElement('textarea','description');
		$description->setLabel('Description:')
					->setAttrib('rows',12)
					->setAttrib('cols',40)
					->setAttrib('style','width:90%');
		
		$create = $this->createElement('submit','create');
		$create->setLabel('Create')
				->setDecorators(array(
							'viewHelper',
								'Errors',
								array('Description', array('tag'=>'', 'escape'=>false)),
								array(array('data'=>'HtmlTag'),
									array('tag'=>'td', 'valign'=>'top', 'style'=> 'background-color:#ffffff;text-align:center','openOnly'=>true,'colspan'=>2,'align'=>'center')),
								//array('Label', array('tag'=>'td')),
								array(array('row'=>'HtmlTag'), array('tag'=>'tr','openOnly'=>true))
				));
				
		$cancel = $this->createElement('button','cancel');
		$cancel->setLabel('Cancel')
				->setDecorators(array(
							'viewHelper',
								'Errors',
								array('Description', array('tag'=>'', 'escape'=>false)),
								array(array('data'=>'HtmlTag'),
									array('tag'=>'td', 'valign'=>'top', 'style'=> 'background-color:#ffffff','closeOnly'=>true)),
								//array('Label', array('tag'=>'td')),
								array(array('row'=>'HtmlTag'), array('tag'=>'tr','closeOnly'=>true))
				));
		
		$this->addElements(array(
						$summary,
						$priority,
						$duedate,
						$components,
						$affectVersions,
						$fixVersions,
						$assignee,
						$reporter,
						$description,
						$id,
						$issuestatus,
						$resolution,
						$create,
						$cancel
		));
		
		$this->setElementDecorators(array(
								'viewHelper',
								'Errors',
								array('Description', array('tag'=>'', 'escape'=>false)),
								array(array('data'=>'HtmlTag'),
									array('tag'=>'td', 'valign'=>'top', 'style'=> 'background-color:#ffffff;text-align:left')),
								array('Label', array('tag'=>'td')),
								array(array('row'=>'HtmlTag'), array('tag'=>'tr'))),
								array('summary', 'priority', 'duedate', 'components', 'affectVersions', 'fixVersions', 'assignee','reporter', 'description')
								);
								
		$this->addDecorators(array(
				'FormElements',
				array('HtmlTag', array('tag' => 'table','width'=>'100%','cellspacing'=>'0','border'=>'0','class'=>'pform')),
				'Form'
		));
	}
}